package com.lancoo.ccas52.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lancoo.ccas52.aspect.LogAnnotation;
import com.lancoo.ccas52.entity.CollegeDealTime;
import com.lancoo.ccas52.entity.PlanTeachingCourseSegment;
import com.lancoo.ccas52.entity.Student;
import com.lancoo.ccas52.pojo.common.PageInfo;
import com.lancoo.ccas52.pojo.vo.*;
import com.lancoo.ccas52.service.CollegeDealTimeService;
import com.lancoo.ccas52.service.CourseService;
import com.lancoo.ccas52.service.MajorService;
import com.lancoo.ccas52.service.PlanTeachingService;
import com.lancoo.ccas52.util.ResponseObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName CoursePlanController
 * @Description 开课计划
 * @Author quin
 * @Date 2022/12/30 17:16
 */
@Api(tags = "开课计划控制器")
@RestController
@RequestMapping("/api/v5.2.1/pc/coursePlan")
public class CoursePlanController {


    @Resource
    private PlanTeachingService planTeachingService;

    @Resource
    private MajorService majorService;

    @ApiOperation("获取教学计划")
    @GetMapping(value = "/teachPlan/getTeacherPlan")
    public ResponseObject<TeachingPlanCount> getTeacherPlan(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                            @ApiParam(value = "学院id 全部不传", required = false) @RequestParam(required = false) String collegeId,
                                                            @ApiParam(value = "0：全部 1:主修  2：辅修", required = false) @RequestParam(required = false) Integer natureId,
                                                            @ApiParam(value = "年级id ", required = false) @RequestParam(required = false) String gradeId) {
        return ResponseObject.ofSuccess(planTeachingService.getPlanTeaching(taskId, collegeId, natureId, gradeId));
    }

    @ApiOperation("确认教学计划")
    @PostMapping(value = "/teachPlan/sure")
    @LogAnnotation(operationType = "15", operationContent = "确定教学计划")
    public ResponseObject<Object> updateTeacherPlan(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                    @ApiParam(value = "教学计划id,逗号分割", required = true) @RequestParam String teachPlanIds,
                                                    @ApiParam(value = "操作状态 0未开启  1已开启", required = true) @RequestParam Integer isEnable) {
        if (StrUtil.isBlank(teachPlanIds)) {
            return ResponseObject.ofFail("教学计划id不能为空");
        }
        String[] split = teachPlanIds.split(",");
        List<Long> teachPlanIdList = new ArrayList<>();
        for (String s : split) {
            teachPlanIdList.add(Long.parseLong(s));
        }
        planTeachingService.updatePlanTeaching(taskId, teachPlanIdList, isEnable);
        return ResponseObject.ofSuccess("修改成功");
    }

    @ApiOperation("添加教学计划对应课程")
    @PostMapping(value = "/addPlanSegCou")
    @LogAnnotation(operationType = "1", operationContent = "添加教学计划对应课程")
    public ResponseObject<List<PlanTeachingCourseSegment>> addPlanSegCou(@ApiParam(value = "中间表", required = true) @RequestBody List<AddPlanSegCon> addPlanSegConList) {
        return ResponseObject.ofSuccess(planTeachingService.addPlanSegCou(addPlanSegConList));
    }

    @ApiOperation("获取没有选择该课程的教学计划")
    @GetMapping(value = "/getPlanTeaching")
    public ResponseObject<List<TeachingPlanDto>> getPlanTeaching(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                 @ApiParam(value = "1课程  2环节", required = true) @RequestParam(required = true) Integer flag,
                                                                 @ApiParam(value = "基础平台课程、环节id", required = false) @RequestParam(required = false) String baseCourseId,
                                                                 @ApiParam(value = "学院id", required = false) @RequestParam(required = false) String collegeId) {
        return ResponseObject.ofSuccess(planTeachingService.getTeachingPlanNoCourse(taskId, flag, baseCourseId, collegeId));
    }

    @ApiOperation("获取课程教学计划情况")
    @GetMapping(value = "/getTeachingPlanByCourse")
    public ResponseObject<List<CampusPlanTeachingVo>> getPlanTeaching(@ApiParam(value = "课程id", required = true) @RequestParam(required = true) Long courseId,
                                                                      @ApiParam(value = "修读性质 1主 2辅修", required = true) @RequestParam(required = true) Integer studyNature,
                                                                      @ApiParam(value = "3预选 4：非预选", required = false) @RequestParam(required = false) Integer teachingClassType) {
        return ResponseObject.ofSuccess(planTeachingService.getTeachingPlanByCourse(courseId, studyNature, teachingClassType));
    }

    @ApiOperation("获取环节教学计划情况")
    @GetMapping(value = "/getTeachingPlanBySegment")
    public ResponseObject<List<CampusPlanTeachingVo>> getTeachingPlanBySegment(@ApiParam(value = "环节id", required = true) @RequestParam(required = true) Long courseId,
                                                                               @ApiParam(value = "修读性质 1主 2辅修", required = true) @RequestParam(required = true) Integer studyNature) {
        return ResponseObject.ofSuccess(planTeachingService.getTeachingPlanBySegment(courseId, studyNature));
    }

    @ApiOperation("获取一个教学计划的学生")
    @GetMapping(value = "/getStudentListByPlanId")
    public ResponseObject<List<StudentGroupClass>> getStudentListByPlanId(@ApiParam(value = "教学计划id", required = true) @RequestParam(required = true) Long teachingPlanId) {
        return ResponseObject.ofSuccess(planTeachingService.getStudentListByPlanId(teachingPlanId));
    }

    @ApiOperation("获取一个课程的学生<不包含该课程已选学生>")
    @GetMapping(value = "/getStudentListByCourse")
    public ResponseObject<List<StudentGroupClass>> getStudentListByCourse(@ApiParam(value = "1课程  2环节", required = true) @RequestParam(required = true) Integer flag,
                                                                          @ApiParam(value = "课程id", required = true) @RequestParam Long courseId,
                                                                          @ApiParam(value = "修读性质：1主修2辅修", required = true) @RequestParam Integer studyNature,
                                                                          @ApiParam(value = "true:显示全部 false:只显示未选", required = true) @RequestParam(defaultValue = "false") boolean isDisplaySelected,
                                                                          @ApiParam(value = "校区id", required = false) @RequestParam(required = false) String campusId) {
        return ResponseObject.ofSuccess(planTeachingService.getStudentListByCourse(flag, courseId, studyNature, campusId,isDisplaySelected));
    }

    @ApiOperation("获取一个课程的学生")
    @GetMapping(value = "/getStudentByCourseAndNature")
    public ResponseObject<List<Student>> getStudentNumByCourseAndNature(@ApiParam(value = "1课程  2环节", required = true) @RequestParam(required = true) Integer flag,
                                                                          @ApiParam(value = "课程id", required = true) @RequestParam Long courseId,
                                                                          @ApiParam(value = "修读性质：1主修2辅修", required = true) @RequestParam Integer studyNature,
                                                                          @ApiParam(value = "校区id", required = false) @RequestParam(required = false) String campusId) {
        return ResponseObject.ofSuccess(planTeachingService.getStudentNumByCourseAndNature(flag, courseId, studyNature, campusId));
    }

    @ApiOperation("获取一个课程辅修的学生")
    @GetMapping(value = "/getMinorStudentByCourseId")
    public ResponseObject<List<Student>> getMinorStudentByCourseId(@ApiParam(value = "课程id", required = true) @RequestParam(required = true) Long courseId) {
        return ResponseObject.ofSuccess(planTeachingService.getMinorStudentByCourseId(courseId));
    }

    @ApiOperation("导出课程开课计划")
    @GetMapping(value = "/excel/course")
    @LogAnnotation(operationType = "14", operationContent = "导出课程开课计划")
    public ResponseObject<String> courseToExcel(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                @ApiParam(value = "学院id ", required = false) @RequestParam(required = false) String collegeId,
                                                @ApiParam(value = "开课单位名字 ", required = false) @RequestParam(required = false) String collegeName,
                                                @ApiParam(value = "课程类别id 传null全部", required = false) @RequestParam(required = false) String courseTypeId,
                                                @ApiParam(value = "课程类别名字", required = false) @RequestParam(required = false) String courseType,
                                                @ApiParam(value = "课程性质 1必修  2选修", required = false) @RequestParam(required = false) Integer courseNature,
                                                @ApiParam(value = "修读性质 1主 2辅修??", required = false) @RequestParam(required = false) Integer studyNature) {
        return ResponseObject.ofSuccess(planTeachingService.courseToExcel(taskId, collegeId, collegeName, courseTypeId, courseType, courseNature, studyNature));
    }

    @ApiOperation("导出环节开课计划")
    @GetMapping(value = "/excel/segment")
    @LogAnnotation(operationType = "14", operationContent = "导出环节开课计划")
    public ResponseObject<String> segmentToExcel(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                 @ApiParam(value = "学院id ", required = false) @RequestParam(required = false) String collegeId,
                                                 @ApiParam(value = "开课单位名字 ", required = false) @RequestParam(required = false) String collegeName,
                                                 @ApiParam(value = "课程类别id 传null全部", required = false) @RequestParam(required = false) String segmentTypeId,
                                                 @ApiParam(value = "课程类别名字", required = false) @RequestParam(required = false) String segmentType) {
        return ResponseObject.ofSuccess(planTeachingService.segmentToExcel(taskId, collegeId, collegeName, segmentTypeId, segmentType));
    }

    @ApiOperation("导出课程申请变更")
    @PostMapping(value = "/excel/courseApply")
    @LogAnnotation(operationType = "14", operationContent = "导出课程申请变更")
    public ResponseObject<String> courseApplyToExcel(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                     @ApiParam(value = "学院id ", required = false) @RequestParam(required = false) String collegeId,
                                                     @ApiParam(value = "开课单位名字 ", required = false) @RequestParam(required = false) String collegeName,
                                                     @ApiParam(value = "课程类别id 传null全部", required = false) @RequestParam(required = false) String courseTypeId,
                                                     @ApiParam(value = "课程类别名字", required = false) @RequestParam(required = false) String courseType,
                                                     @ApiParam(value = "课程性质 1必修  2选修", required = false) @RequestParam(required = false) Integer courseNature,
                                                     @ApiParam(value = "修读性质 1主 2辅修??", required = false) @RequestParam(required = false) Integer studyNature,
                                                     @ApiParam(value = "课程id", required = true) @RequestBody List<Long> courseIds) {
        return ResponseObject.ofSuccess(planTeachingService.courseApplyToExcel(taskId, collegeId, collegeName, courseTypeId, courseType, courseNature, studyNature,courseIds));
    }

    @ApiOperation("导出环节申请变更")
    @PostMapping(value = "/excel/segmentApply")
    @LogAnnotation(operationType = "14", operationContent = "导出环节申请变更")
    public ResponseObject<String> segmentApplyToExcel(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                      @ApiParam(value = "学院id ", required = false) @RequestParam(required = false) String collegeId,
                                                      @ApiParam(value = "开课单位名字 ", required = false) @RequestParam(required = false) String collegeName,
                                                      @ApiParam(value = "课程类别id 传null全部", required = false) @RequestParam(required = false) String segmentTypeId,
                                                      @ApiParam(value = "课程类别名字", required = false) @RequestParam(required = false) String segmentType,
                                                      @ApiParam(value = "环节id", required = true) @RequestBody List<Long> courseIds) {
        return ResponseObject.ofSuccess(planTeachingService.segmentApplyToExcel(taskId, collegeId, collegeName, segmentTypeId, segmentType,courseIds));
    }


}
